﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace RogueWarrior.View
{
    class DisplayableEntity : IDisplayable
    {
        int mFrameSize = 96;
        int mRowNumber = 0;
        int mFrameNumber = 0;
        int mFrameRate = 10;
        int mFrameCounter = 0;

        Rectangle mFrame;
        Texture2D mSpriteTexture;

        public DisplayableEntity(Texture2D spriteTexture)
        {
            mSpriteTexture = spriteTexture;
            mFrame = new Rectangle(0, 0, this.mFrameSize, this.mFrameSize);
        }

        public void setFrameNumber(int frameNumber)
        {
            mFrameNumber = frameNumber;
        }

        public Texture2D getSpriteTexture()
        {
            return mSpriteTexture;
        }

        public Rectangle getFrame()
        {
            return mFrame;
        }

        public void update()
        {
            this.startAnimation();
        }

        public void startAnimation()
        {
            mFrameCounter += 1;
            if (mFrameCounter == mFrameRate)
            {
                int intX = mFrameNumber * this.mFrameSize;
                mFrameNumber += 1;
                if (intX == 672)
                {
                    mFrameNumber = 0;
                }

                int intY = this.getRowNumber() * this.mFrameSize;

                mFrame = new Rectangle(intX, intY, this.mFrameSize, this.mFrameSize);

                mFrameCounter = 0;
            }
        }

        private int getRowNumber()
        {
            return this.mRowNumber;
        }

        public void setRowNumber(int rowNumber)
        {
            mRowNumber = rowNumber;
        }


    }
}
